﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Infrastructure;
using Presentation;

namespace WinClient
{
    public partial class ClientForm : Form, IView
    {
        public ClientForm()
        {
            InitializeComponent();
            new Presenter(this, new TxtLogger());
            listView.Clear();
            listView.View = View.Details;
            listView.Columns.Add("No");
            listView.Columns.Add("     Record     ");
            listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }

        public string FromValue
        {
            get { return inputValue.Text; }
        }

        public string FromType
        {
            get { return inputType.Text; }
        }

        public string ToType
        {
            get { return outputType.Text; }
        }

        public string ToValue
        {
            set { outputValue.Text = value; }
        }

        public string FileName
        {
            get { return fileName.Text; }
        }

        public string ErrorMessage
        {
            set { errorMassege.Text = value; }
        }

        public string Action
        {
            set
            {
                var i = listView.Items.Count;
                listView.Items.Add(Convert.ToString(i));
                listView.Items[i].SubItems.Add(value);
            }
        }

        public event Action OnConvertClick;
        public event Action OnWriteLogToFile;
        public event Action OnTxtClick;
        public event Action OnHtmlClick;

        public void ClearError()
        {
            ErrorMessage = "";
        }

        private void convertButton_Click(object sender, EventArgs e)
        {
            OnConvertClick();
        }

        private void writeLogTxt_Click(object sender, EventArgs e)
        {
            OnWriteLogToFile();
        }

        private void htmlFormat_CheckedChanged(object sender, EventArgs e)
        {
            if (htmlFormat.Checked)
            {
                OnHtmlClick();
                fileName.Text = "HtmlLog.html";
            }
        }

        private void txtFormat_CheckedChanged(object sender, EventArgs e)
        {
            if (txtFormat.Checked)
            {
                OnTxtClick();
                fileName.Text = "TxtLog.txt";
            }
        }

        public ILog CreateTxtLogger()
        {
            return new TxtLogger();
        }
        public ILog CreateHtmlLogger()
        {
            return new HtmlLogger();
        }
    }
}
